package cf.huzpsb.bcgod;

import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;

public class VipCMD extends Command {
    public VipCMD(String name, String permission, String... aliases) {
        super(name, permission, aliases);
    }

    public void execute(CommandSender sender, String[] args) {
        if (!(sender instanceof ProxiedPlayer)) {
            sender.sendMessage("§c后台无法使用此命令");
            return;
        } else if (((ProxiedPlayer) sender).getServer().getInfo().getName().equalsIgnoreCase(Main.login)) {
            sender.sendMessage("§c登录区域禁止使用!");
            return;
        }
        if (args.length != 1) {
            sender.sendMessage("§c错误:参数错误.");
            return;
        }
        if (args[0].contains(".")) {
            sender.sendMessage("§c错误:检测到注入.");
            return;
        }
        int nh;
        if (Main.horncfg.contains(sender.getName())) {
            nh = Main.horncfg.getInt(sender.getName());
        } else {
            sender.sendMessage("§c错误:你现在没有欢乐券.");
            return;
        }
        if (!Main.config.contains("bcgod.vips." + args[0] + ".cost")) {
            sender.sendMessage("§c错误:你输入的氪金项目不存在.");
            return;
        }
        nh = nh - Main.config.getInt("bcgod.vips." + args[0] + ".cost");
        if (nh < 0) {
            sender.sendMessage("§c错误:你没有足够多的欢乐券.");
            return;
        }
        if (nh == 0) {
            Main.horncfg.set(sender.getName(), null);
        } else {
            Main.horncfg.set(sender.getName(), nh);
        }
        BungeeCord.getInstance().getPluginManager().dispatchCommand(BungeeCord.getInstance().getConsole(), Main.config.getString("bcgod.vips." + args[0] + ".cmd").replace("%p", sender.getName()));
        sender.sendMessage("§a[huzpsb]>氪金 " + args[0] + " 成功!你现在的欢乐券个数为: " + nh);
    }
}
